package ifmo.group5512;

import ifmo.group5512.entity.Order;
import ifmo.group5512.dao.impl.OrderDAO;
import ifmo.group5512.entity.OrderHistory;
import ifmo.group5512.entity.OrderProductTable;
import ifmo.group5512.entity.Product;
import ifmo.group5512.util.DaoFactory;
import net.sf.json.JSON;
import net.sf.json.JSONSerializer;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;

public class Main {
	public static void saveDatabase() 
    {
//        try {
            // Write out Array to the database
            /* This step will read hibernate.cfg.xml and prepare hibernate for use*/
            
		Collection orders = DaoFactory.getInstance().getOrderDAO().getAllOrders();
		
//		OrderDAO orderDao = (OrderDAO)DaoFactory.getInstance().getOrderDAO();
//		Order order = orderDao.getOrderById(1);
//		System.out.println(order.getBeginDate());
//		
//		Product product = orderDao.getProductById(1);
//		
//		Set<Product> products = new HashSet<Product>();
//		products.add(product);
//		OrderProductTable orderProductTable = new OrderProductTable();
//		//order.setId(//id)
//		orderProductTable.setOrders(order);
//		orderProductTable.setProducts(products);
//		
//		orderDao.saveOrder(orderProductTable);
//		
		//DaoFactory.getInstance().getOrderDAO().saveOrder();	
//            for(Object obj:orders){
//                System.out.println(((OrderProductTable)obj).getId());
//                //DaoFactory.getInstance().getOrderDAO().getComplexityForOrder((Order)obj);
//            }

            
            
           // JSONSerializer serializer = new JSONSerializer();
            //JSON obj = serializer.toJSON(new Order(5,"sasha"));
            //System.out.println(obj.toString());
        
//            for(int i = 0; i < animalsList.size(); i++)
//            {
//                try {
//                    /*Create new instance of Contact and set 
//                      values in it by reading them from form object*/
//                    System.out.println("Inserting Record");
//                    session.save(animalsList.get(i));
//                }catch(Exception e){
//                    System.out.println(e.getMessage());
//                }
//            }
//        }
//        catch(Exception e){
//            System.out.println(e.getMessage());
//        }
//        finally{
//            // Actual contact insertion will happen at this step
//            session.flush();
//            session.close();
//        }
    }


	public static void main(String[] args) {
		// TODO Auto-generated method stub
		saveDatabase();
		System.out.println("asdas");
	}

}
